package cn.hahah.module.blog.app.controller;

import cn.hahah.framework.common.pojo.CommonResult;
import cn.hahah.module.blog.app.service.BlogAuthService;
import cn.hahah.module.blog.controller.admin.users.vo.UsersPageReqVO;
import cn.hahah.module.blog.controller.admin.users.vo.UsersRespVO;
import cn.hahah.module.blog.controller.admin.users.vo.UsersSaveReqVO;
import cn.hahah.module.blog.dal.dataobject.users.UsersDO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import org.springframework.web.bind.annotation.*;



@RestController
@Tag(name = "博客验证")
@RequestMapping("/public/auth")  // 基础路径
public class BlogAuthController {

    @Resource
    private BlogAuthService blogAuthService;

    /**用户登录*/
    @PostMapping("/login")
    @Operation(summary = "用户登录")
    public CommonResult<UsersRespVO> login(
            @RequestParam @NotBlank(message = "用户名不能为空") String username,
            @RequestParam @NotBlank(message = "密码不能为空") String password) {

        return blogAuthService.login(username, password);
    }

    /**用户注册*/
    @PostMapping("/register")
    @Operation(summary = "用户注册")
    public CommonResult<UsersRespVO> register(
            @RequestBody @Valid UsersSaveReqVO usersSaveReqVO) {
        return blogAuthService.register(usersSaveReqVO);
    }


    /**用户找回密码*/
    @PostMapping("/resetPassword")
    @Operation(summary = "找回密码")
    CommonResult<String> resetPassword(
            @RequestParam @NotBlank(message = "用户名不能为空") String username,
            @RequestParam @NotBlank(message = "密码不能为空") String newPassword) {
        return blogAuthService.resetPassword(username, newPassword);
    }

    /**验证接口*/
    @GetMapping("/validateEmali")
    @Operation(summary = "验证接口")
    public CommonResult<String> validateEmali(
            @RequestParam @NotBlank(message = "密码不能为空") String newPassword,
            @RequestParam @NotBlank(message = "token不能为空") String token) {
        return blogAuthService.validateEmail(newPassword, token);
    }


}